package
{
	import UI.List;
	import UI.ListItem;
	import UI.ScrollBarV;
	
	import flash.display.Bitmap;
	import flash.display.Sprite;
	import flash.display.StageAlign;
	import flash.display.StageScaleMode;
	import flash.events.Event;
	import flash.events.MouseEvent;
	
	public class TestList extends Sprite
	{
		[Embed(source="./assets/scrollBar.png")]
		private	var scrollBtnImg:Class;
		
		[Embed(source="./assets/scrollBar_bg.png")]
		private	var scrollBgImg:Class;
		
		[Embed(source="./assets/scrollBar_upArrow.png")]
		private	var scrollUpImg:Class;
		
		[Embed(source="./assets/scrollBar_downArrow.png")]
		private	var scrollDownImg:Class;
		
		private	var _addTotal:int = 0;
		private	var _addFlag:Boolean = true;
		private	var _list:List = null;
		public function TestList()
		{
			super();
			this.stage.align = StageAlign.TOP_LEFT;
			this.stage.scaleMode = StageScaleMode.NO_SCALE;
			var list:List = new List(200, 290);
			list.x = 20;
			list.y = 20;
			for(var i:int = 0; i < 00;i++){
				list.addItem(new ListItem("test"+i));
			}
			trace("list width:"+list.width+", height:"+list.height);
			var scrollBtnPic:Bitmap = new this.scrollBtnImg();
			var scrollBgPic:Bitmap = new this.scrollBgImg();
			var scrollUpPic:Bitmap = new this.scrollUpImg();
			var scrollDownPic:Bitmap = new this.scrollDownImg();
			var scrollBar:ScrollBarV = new ScrollBarV(15, list.height, scrollBtnPic, scrollBgPic,
				scrollUpPic, scrollDownPic);
			scrollBar.scrollView = list;
			scrollBar.x = list.x+list.width;
			scrollBar.y = list.y;
			
			this.addChild(scrollBar);
			this.addChild(list);
			
			this.addEventListener(Event.ENTER_FRAME, onEnterFrame);
			list.addEventListener(MouseEvent.DOUBLE_CLICK, onDoubleClick);
			this._list = list;
		}
		
		public	function	onDoubleClick(evt:MouseEvent):void{
			var index:int = this._list.getSelectedIndex();
			trace(this._list.getListItemFromIndex(index).text);
		}
		
		public	function	onEnterFrame(evt:Event):void{
			var list:List = this.getChildAt(1) as List;
			//list.scrollV(1);
//			if (this._addFlag == true && this._addTotal < list.documentHeight-list.viewHeight){
//				list.scrollV(1);
//				this._addTotal+= 1;
//			}
//			else if (this._addFlag == true && this._addTotal >= list.documentHeight-list.viewHeight){
//				this._addFlag = false;
//			}
//			else if (this._addFlag == false && this._addTotal > 0){
//				list.scrollV(-1);
//				this._addTotal -=1;
//			}
//			else if (this._addFlag == false && this._addTotal <= 0){
//				this._addFlag = true;
//			}
		}
	}
}          